package com.xuan.friend.controller.user;

import com.xuan.common.core.constants.HttpConstants;
import com.xuan.common.core.controller.BaseController;
import com.xuan.common.core.domain.R;
import com.xuan.common.core.domain.TableDataInfo;
import com.xuan.common.core.exception.BusinessException;
import com.xuan.friend.aop.CheckUserStatus;
import com.xuan.friend.domain.contest.dto.ContestQueryDTO;
import com.xuan.friend.domain.user.dto.UserContestEnterDTO;
import com.xuan.friend.service.user.UserContestService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user/contest")
public class UserContestController extends BaseController {


    @Resource
    private UserContestService userContestService;


    @CheckUserStatus
    @PostMapping("/enter")
    public R<Void> enterContest(@RequestBody UserContestEnterDTO userContestEnterDTO, @RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        if (userContestEnterDTO == null || userContestEnterDTO.getContestId() == null) {
            throw new BusinessException("参数为空");
        }
        return toR(userContestService.enterContest(userContestEnterDTO.getContestId(), token));
    }


    @GetMapping("/list")
    public TableDataInfo redisListContest(ContestQueryDTO contestQueryDTO) {
        if (contestQueryDTO == null) {
            throw new BusinessException("参数为空");
        }
        return userContestService.redisListContest(contestQueryDTO);
    }


}
